package com.longyue.ms.app.web;

import com.longyue.ms.app.entity.CarType;
import com.longyue.ms.app.service.CarTypeService;
import com.longyue.ms.app.vo.CarTypeParam;
import com.longyue.ms.common.bean.AjaxResult;
import com.longyue.ms.common.bean.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description
 * @Author lishengpeng
 * @Date 2023/1/31 17:57
 */
@RestController()
@RequestMapping("/carType")
public class CatTypeController {

    @Autowired
    private CarTypeService carTypeService;

    @PostMapping("/getPageData")
    public Pagination<CarType> getPageData(@RequestBody CarTypeParam carTypeParam) throws Exception {
        return carTypeService.getPageData(carTypeParam);
    }

    @GetMapping(value = "/addType")
    public AjaxResult addType(String typeName) throws Exception {
        CarType carType = new CarType();
        carType.setTypeName(typeName);
        return carTypeService.addCarType(carType);
    }

    @PostMapping("/deleteById")
    public AjaxResult deleteById(Integer id) throws Exception {
        return carTypeService.deleteById(id);
    }

    @PostMapping("/updateCarType")
    public AjaxResult updateCarType(CarType carType) throws Exception {
        return carTypeService.updateType(carType);
    }

    @GetMapping("/getById")
    public CarType getCardRecordById(Integer id) throws Exception {
        return carTypeService.getById(id);
    }
}
